package org.sg20.utils;


/**
 * 解析各种输入
 */
public class ParseText {

    //由于PageRank和标签传播都需要构建图,都需要解析图的边和点,故单独拎出来一个模块

    /**
     * 解析边
     * 将 "[悟空,0.5|八戒,0.5]" 转为 Edge(悟空,0.5),Edge(八戒,0.5)
     */
    public static Edge[] parseEdges(String strEdges) {
        //TODO PageRank和LPA
        strEdges = strEdges.substring(1, strEdges.length() - 1);
        String[] temps = strEdges.split("\\|");
        Edge[] res = new Edge[temps.length];
        for (int i = 0; i < res.length; i++) {
            String[] temp = temps[i].split(",");
            res[i] = new Edge(temp[0], Double.parseDouble(temp[1]));
        }
        return res;
    }


    /**
     * 解析点
     * 将 "唐僧,2" 解析为 Dot(唐僧,2)
     */
    @Deprecated
    public static PrDot parsePRDot(String strDot) {
        //TODO PageRank
        return null;
    }

    /**
     * 解析点
     * 将 "唐僧[0,0.3|1,0.4|2,0.4]转为 Dot(唐僧,Array(0.3,0.4,0.4))
     */
    @Deprecated
    public static LpaDot parseLPADot(String strDot) {
        //TODO LPA
        return null;
    }

    /**
     * 解析标签概率向量
     * [pr1,pr2,...]->LpaDotVal(Array(pr1,pr2,...))
     */
    public static LpaDotVal parseLPADotVal(String strVals){
        strVals=strVals.substring(1,strVals.length()-1);
        String[] temp=strVals.split(",");
        double[] vals=new double[temp.length];
        for(int i=0;i<vals.length;i++)vals[i]=Double.parseDouble(temp[i]);
        return new LpaDotVal(vals);
    }
}
